package com.white.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.white.bean.ThumbsUp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ThumbsUpMapper extends BaseMapper<ThumbsUp> {
    String TABLE_NAME = " thumbsUp ";
    int LIMIT = 10;
    String CREATE_TIME = "createTime";

    @Select("select * from" + TABLE_NAME + "where userId = #{userId} and beThumbsUpId = #{beThumbsUpId} order by " + CREATE_TIME + " desc limit " + LIMIT)
    List<ThumbsUp> isLikeArticle(Long userId, Long beThumbsUpId);

    @Delete("delete from" + TABLE_NAME + "where userId = #{userId} and beThumbsUpId = #{beThumbsUpId} and type = #{type}")
    void myDelete(Long userId, Long beThumbsUpId, int type);

    @Insert("insert" + TABLE_NAME + "(userId, beThumbsUpId, type) values(#{userId}, #{beThumbsUpId}, #{type})")
    void save(ThumbsUp thumbsUp);

    @Select("select * from" + TABLE_NAME + "where userId = #{userId} order by " + CREATE_TIME + " desc limit " + LIMIT)
    List<ThumbsUp> getLikeByUserId(Long userId);

    @Select("select * from" + TABLE_NAME + "where userId = #{userId} and beThumbsUpId = #{beThumbsUpId} and type = #{type} limit 1")
    ThumbsUp isLikeComment(Long userId, Long beThumbsUpId, int type);
}
